package com.hy.mydesktop.client.component.mvc.factory;

import java.util.Iterator;
import java.util.List;

import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.Layout;
import com.extjs.gxt.ui.client.widget.Window;
import com.hy.mydesktop.client.component.event.AppEvents;
import com.hy.mydesktop.client.component.meta.AccordionPanelModelEnum;
import com.hy.mydesktop.client.component.meta.WindowModelEnum;
import com.hy.mydesktop.client.component.mvc.controller.meta.WindowControllerModelEnum;
import com.hy.mydesktop.client.component.mvc.factory.util.ControllerFactoryUtil;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.client.mvc.desktop.DesktopController;
import com.hy.mydesktop.client.mvc.window.WindowController;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;

/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-8-29；时间：下午03:55:18</li>
 * <li>类型名称：WindowFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class DesktopControllerFactory {
/**
 * registerEventTypes(AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);
 * 1 注册事件
 * 2 handleEvent
 * 
 */
	
	public static Controller createDesktopController(GxtComponentControllerMetaNodeModel gxtComponentControllerMetaNodeModel){
		
		return configureDesktopController(gxtComponentControllerMetaNodeModel);
	}
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：对窗口的属性进行配置</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-8-29；时间：下午下午03:56:36</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static Controller configureDesktopController(GxtComponentControllerMetaNodeModel gxtComponentControllerMetaNodeModel){
		
		DesktopController desktopController = createDefaultDesktopController();
		return ControllerFactoryUtil.configureWindow(desktopController, gxtComponentControllerMetaNodeModel);

		
		//为Controller，添加它对应的视图View中，包含的控件的元数据
		/*if(gxtComponentMetaNodeModel.get(WindowControllerModelEnum.GXTCOMPONENTMETANODEMODEL.name().toLowerCase())!=null){
			
			GxtComponentMetaNodeModel subGxtComponentMetaNodeModel = gxtComponentMetaNodeModel.get(WindowControllerModelEnum.GXTCOMPONENTMETANODEMODEL.name().toLowerCase());
			desktopController.setGxtComponentMetaNodeModel(subGxtComponentMetaNodeModel);
		}
		//为Controller，添加它对应的视图View的标识 ViewData
		if(gxtComponentMetaNodeModel.get(WindowControllerModelEnum.VIEWDATA.name().toLowerCase())!=null){
			
			String viewDataCode = gxtComponentMetaNodeModel.get(WindowControllerModelEnum.VIEWDATA.name().toLowerCase());
			desktopController.setViewData(viewDataCode);
		
		}
		//为Controller添加它的标识 id
		if(gxtComponentMetaNodeModel.get(WindowControllerModelEnum.ID.name().toLowerCase())!=null){
			
			String id = gxtComponentMetaNodeModel.get(WindowControllerModelEnum.ID.name().toLowerCase());
			desktopController.setId(id);
		
		}
		//注册WindowController，需要监听的事件
		if(gxtComponentMetaNodeModel.get(WindowControllerModelEnum.REGISTEREVENTTYPES.name().toLowerCase())!=null){
			
			List<String> appEventCodes = gxtComponentMetaNodeModel.get(WindowControllerModelEnum.REGISTEREVENTTYPES.name().toLowerCase());
			for (String code : appEventCodes) {
				Integer i = Integer.valueOf(code);
				switch (i) {
		            case 1://Integer.valueOf("0001")
		            	desktopController.addRegisterEventType(AppEvents.DESKTOP_USER_LOGIN);
		            	
		                break;
		            case 2://Integer.valueOf("0002")
		            	desktopController.addRegisterEventType(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER);	
		                break;
		            case 3://Integer.valueOf("0003")
		            	desktopController.addRegisterEventType(AppEvents.DESKTOP_SHORTCUT_ONCLICK_INIT);	
		                break;
		            case 101://Integer.valueOf("0101")
		            	desktopController.addRegisterEventType(AppEvents.WINDOW_ININT);
		                break;
	           		           
		            default:
		                break;
		        }
			}
		
		}
		
		if(gxtComponentMetaNodeModel.get(WindowControllerModelEnum.ID.name().toLowerCase())!=null){
			
			String id = gxtComponentMetaNodeModel.get(WindowControllerModelEnum.ID.name().toLowerCase());
			desktopController.setId(id);
		
		}
		return desktopController;*/
	}
	
	
	private static DesktopController createDefaultDesktopController(){
		DesktopController desktopController = new DesktopController();
		
		return desktopController;
	}
}
